package com.items.blog.model;

import com.items.blog.common.Constants;
import lombok.Data;

@Data
public  class Result<T> {

    private int code;//200成功 -1失败
    private String errorMsg;
    private T data;//数据



    //成功 声明泛型 返回数据
    public static <T> Result<T> success(T data){
        Result result =new Result();

        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        result.setErrorMsg("");
        return result;
    }

    //失败不返回数据
    public static <T> Result<T> fail(String errorMsg){
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);

        result.setErrorMsg(errorMsg);
        return result;
    }

    //失败之后返回数据
    public static  <T> Result<T> fail(String errorMsg,T data){
        Result result =new Result();
        result.setCode(Constants.RESULT_FAIL);

        result.setErrorMsg(errorMsg);
        result.setData(data);
        return result;
    }
}
